<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/6 0006
 * Time: 13:43
 */

namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Http\Requests\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;

class UserController extends Controller
{
    public function edit($id){
        $user_message = DB::table('user')->where('id',$id)->first();
       // dd($user_message);
        return view('useredit');
    }

    public function upload(Request $request){
        $file = $request->file('image');
        if($file->isValid()){
            $originname = $file->getClientOriginName();     //原文件名
            $ext = $file->getClientOriginalExtension();     //扩展名
            $mimetype = $file->getClientMimeType();         //mimetype
            $realpath = $file->getRealPath();               //临时绝对路径

            $filename = date('YmdHis',time()).'-'.uniqid().'-'.$ext;    //拼接文件名
            $isSuccess = Storage::disk('upload')->put($filename,file_get_contents($realpath));
            if($isSuccess){
                return response()->json(['src'=>$filename]);
            }
        }
    }
}